const http = require('http');
const url = require('url');

const server = http.createServer((req, res) => {
    console.log('请求行----start-----')
    console.log(req.method)
    console.log(req.url)
    const { pathname, query } = url.parse(req.url, true)
    console.log(pathname, query);
    console.log('请求行----end---')
    console.log('请求头---start---')
    console.log(req.headers)
    console.log('请求头----end---')
    //大文件的分片上传
    const chunk = []
    console.log('获取请求体---start---')
    req.on('data', (data) => {
        chunk.push(data)
    })
    req.on('end', () => {
        console.log(Buffer.concat(chunk).toString())
        console.log('获取请求体 ---end---')
    })
    // 设置响应头
    res.statusCode = 200;
    res.statusMessage = 'my define';
    res.setHeader('MyHeader', 100)
    res.write('hello')
    res.write('world')
    res.end('ok')
})
server.listen(3000, () => {
    console.log('server start on port 3000')
})